/*
 * @Description: 表格行按钮配置
 * @Author: HuiSir<https://gitee.com/huisir001>
 * @Date: 2025-07-28 21:55:31
 * @LastEditTime: 2025-09-15 18:04:48
 */
import { defineRowBtnsOptions } from "@/components/TablePage/predefined";
import useEditOptions from "./useEditOptions";
import { updateAdmin, delAdmin } from "@/api/sys";

/* eslint-disable @typescript-eslint/no-explicit-any */
export default defineRowBtnsOptions(
  (getRolesAndDepts: () => Awaitable<any>) => ({
    editRequest: updateAdmin,
    delRequest: delAdmin,
    editDialogProps: { title: "编辑管理员账号" },
    editFormOptions: useEditOptions(),
    beforeShowEditDialog: async (_rowData, editDialogOptions) => {
      editDialogOptions.value.find((item) => item.key == "password")!.hide =
        true;
      await getRolesAndDepts();
    },
    beforeEditSubmit(formData) {
      const {
        id,
        status,
        accountNo,
        deptId,
        roleIds,
        name,
        phone,
        sex,
        headImg,
      } = formData.value as AdminInfo;

      formData.value = {
        id,
        status,
        accountNo,
        deptId,
        roleIds,
        name,
        phone,
        sex,
        headImg,
      };
    },
  })
);
